package com.ruoyi.web.controller.system;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.SysAppClassification;
import com.ruoyi.system.service.ISysAppClassificationService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 分类信息Controller
 * 
 * @author ruoyi
 * @date 2020-08-15
 */
@Controller
@RequestMapping("/system/classification")
public class SysAppClassificationController extends BaseController
{
    private String prefix = "system/classification";

    @Autowired
    private ISysAppClassificationService sysAppClassificationService;

    @RequiresPermissions("system:classification:view")
    @GetMapping()
    public String classification()
    {
        return prefix + "/classification";
    }

    /**
     * 查询分类信息列表
     */
    @RequiresPermissions("system:classification:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(SysAppClassification sysAppClassification)
    {
        startPage();
        List<SysAppClassification> list = sysAppClassificationService.selectSysAppClassificationList(sysAppClassification);
        return getDataTable(list);
    }

    /**
     * 导出分类信息列表
     */
    @RequiresPermissions("system:classification:export")
    @Log(title = "分类信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(SysAppClassification sysAppClassification)
    {
        List<SysAppClassification> list = sysAppClassificationService.selectSysAppClassificationList(sysAppClassification);
        ExcelUtil<SysAppClassification> util = new ExcelUtil<SysAppClassification>(SysAppClassification.class);
        return util.exportExcel(list, "classification");
    }

    /**
     * 新增分类信息
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存分类信息
     */
    @RequiresPermissions("system:classification:add")
    @Log(title = "分类信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(SysAppClassification sysAppClassification)
    {
        return toAjax(sysAppClassificationService.insertSysAppClassification(sysAppClassification));
    }

    /**
     * 修改分类信息
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        SysAppClassification sysAppClassification = sysAppClassificationService.selectSysAppClassificationById(id);
        mmap.put("sysAppClassification", sysAppClassification);
        return prefix + "/edit";
    }

    /**
     * 修改保存分类信息
     */
    @RequiresPermissions("system:classification:edit")
    @Log(title = "分类信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(SysAppClassification sysAppClassification)
    {
        return toAjax(sysAppClassificationService.updateSysAppClassification(sysAppClassification));
    }

    /**
     * 删除分类信息
     */
    @RequiresPermissions("system:classification:remove")
    @Log(title = "分类信息", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(sysAppClassificationService.deleteSysAppClassificationByIds(ids));
    }
}
